package com.zgkxzx.mvpbase.model.impl;

import com.zgkxzx.mvpbase.model.IGetDataModel;
import com.zgkxzx.mvpbase.model.OnBaseCallBack;

import rx.Observable;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action1;
import rx.schedulers.Schedulers;

/**
 * 创建者 zgkxzx
 * 日期   2017-04-01
 * 描述
 */

public class ObtainDataModelImpl implements IGetDataModel {

    public ObtainDataModelImpl() {

    }

    @Override
    public void getSumResult(final OnBaseCallBack<String> onBaseCallBack) {
        Observable.create(new Observable.OnSubscribe<String>() {
            @Override
            public void call(final Subscriber<? super String> subscriber) {
                int sum = 0;
                for (int i = 0; i < 100; i++)
                    sum += i;
                subscriber.onNext(sum + "");
                subscriber.onCompleted();
            }
        }).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Action1<String>() {
                    @Override
                    public void call(String result) {
                        onBaseCallBack.onSuccess(result);

                    }
                });
    }
}
